package com.db.priceApp.domain.clientDataBasa;

import java.nio.channels.SelectionKey;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentSkipListSet;

public class ClientProfile {
	private ConcurrentSkipListSet<String> subscribtions;
	private String login;
	private SelectionKey key;
	private Long lastTransmitionTime;
	
	public ClientProfile(String login, final Set<String> clientSubscritions) {
		
		this.login = login;
		subscribtions = new ConcurrentSkipListSet<String>();
		subscribtions.addAll(clientSubscritions);
		lastTransmitionTime = 0l;
	}	

	public ClientProfile() {
		this("", new HashSet<String>());
	}

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public SelectionKey getSelectionKey() {
		return key;
	}

	public void setSelectionKey(SelectionKey sk) {
		this.key = sk;
	}


	public boolean subscribe(String instrName) throws IllegalArgumentException {
		return subscribtions.add(instrName);
	}
	
	public boolean unsubscribe(String instrName) throws IllegalArgumentException {
		return subscribtions.remove(instrName);
	}
	
	public boolean isSubscribed (String instrName) throws IllegalArgumentException {		
		return subscribtions.contains(instrName);
	}
	
	public Set<String> getSubscribtions(){
		return Collections.unmodifiableSet(subscribtions);
	}

	public Long getLastTransmitionTime() {
		return lastTransmitionTime;
	}

	public void setLastTransmitionTime(Long lastTransmitionTime) {
		this.lastTransmitionTime = lastTransmitionTime;
	}

}
